package org.wei.db.mongo;

import java.lang.reflect.Type;

import com.google.gson.Gson;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;

public class DocumentConverter {
	private static Gson gson = new Gson();

	public static <T> T dbObject2Bean(DBObject dbObject, Type type) {
		return gson.fromJson(dbObject.toString(), type);
	}

	public static DBObject bean2DbObject(Object object) {
		String json = gson.toJson(object);
		return (DBObject) JSON.parse(json);
	}
}
